package framework.view.components.graphics
{
import flash.display.Loader;
import flash.events.Event;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;

import utils.URLUtil;

/**
 * SWF
 * @author jliang
 * 
 */
public class SWF extends Asset
{
	//==========================================================================
	//  Class constants
	//==========================================================================
	public static const EXTERNAL_LIBS:String = "externalLabs";
	
	public static const SINGLE:String = "single";
	
	public static const MODULE:String = "module";
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function SWF()
	{
		super();
	}
	//==========================================================================
	//  Properties
	//==========================================================================
	private var _mode:String = SWF.SINGLE;

	public function get mode():String
	{
		return _mode;
	}

	public function set mode(value:String):void
	{
		_mode = value;
	}
	
	private var swfAppDomain:ApplicationDomain;

	asset_ns function set appDomain(value:ApplicationDomain):void
	{
		swfAppDomain = value;
		if (value) _isLoaded = true;
	}

	public function get appDomain():ApplicationDomain
	{
		return swfAppDomain;
	}

	public function getClassRef(value:String):Class
	{
		return swfAppDomain.getDefinition(value) as Class;
	}
	//==========================================================================
	//  Overridden methods: Asset
	//==========================================================================	
	override public function load():void
	{		
		loader = new Loader();
		setupEventListener();
		
		var context:LoaderContext = new LoaderContext();
		if (mode == MODULE)
		{	
			context.applicationDomain = ApplicationDomain.currentDomain;
		}
		else
		{
			context.applicationDomain = new ApplicationDomain();
		}
		
		loader.load(URLUtil.getRequest(url), context);
	}
	
	override protected function loadedHandler(event:Event):void
	{
		swfAppDomain = loader.contentLoaderInfo.applicationDomain;
		super.loadedHandler(event);
	}
}
}


